package com.zzw.basic.security;

import org.junit.Test;
import org.springframework.util.DigestUtils;
import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
import java.util.UUID;

/**
 * @author zzw
 * @see
 * @since 2018/1/22
 */
public class Md5Test {
    public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        //确定计算方法
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        BASE64Encoder base64en = new BASE64Encoder();
        //加密后的字符串
        String newstr=base64en.encode(md5.digest("1234567890".getBytes("utf-8")));
        System.out.println(newstr);

        String md5Str = DigestUtils.md5DigestAsHex("!Qaz2wsx".getBytes("utf-8"));
        System.out.println(md5Str);
        System.out.println(getCard());
        System.out.println((int)((Math.random()*9+1)*100000));
    }

    //生成随机数
    public static String getCard(){
        Random rand=new Random();//生成随机数
        String cardNnumer="";
        for(int a=0;a<6;a++){
            cardNnumer+=rand.nextInt(10);//生成6位数字
        }
        return cardNnumer;
    }

    @Test
    public void test1(){
        String s = "您正在重置系统密码，重置后的密码:{0}，为了保障您的账户安全，建议登录之后进行密码修改【江苏电信云资源综合支撑系统】";
        String conent = s.replaceAll("\\{0\\}", "12313");
        System.out.println(conent);
    }

    @Test
    public void test2(){
        System.out.println(UUID.randomUUID().toString());
        System.out.println(UUID.randomUUID());
        System.out.println(UUID.randomUUID());
    }
}
